package com.isdepci.project.carbon.controller;

import com.isdepci.common.utils.poi.ExcelUtil;
import com.isdepci.framework.aspectj.lang.annotation.Log;
import com.isdepci.framework.aspectj.lang.enums.BusinessType;
import com.isdepci.framework.web.controller.BaseController;
import com.isdepci.framework.web.domain.AjaxResult;
import com.isdepci.framework.web.page.TableDataInfo;
import com.isdepci.project.carbon.domain.BRecyclingCarbon;
import com.isdepci.project.carbon.domain.param.WeatherDataExcel;
import com.isdepci.project.carbon.service.IBRecyclingCarbonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 回收利用碳汇Controller
 *
 * @author isdepci
 * @date 2025-03-29
 */
@RestController
@RequestMapping("/recycling/carbon")
public class BRecyclingCarbonController extends BaseController
{
    @Autowired
    private IBRecyclingCarbonService bRecyclingCarbonService;



    /**
     * 回收利用碳汇计算
     */
    @GetMapping("/calRecyclingCarbon")
    public AjaxResult calRecyclingCarbon(@RequestParam Long projectId) {
        return bRecyclingCarbonService.calRecyclingCarbon(projectId);
    }


    /**
     * 查询回收利用碳汇列表
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:list')")
    @GetMapping("/list")
    public TableDataInfo list(BRecyclingCarbon bRecyclingCarbon)
    {
        startPage();
        List<BRecyclingCarbon> list = bRecyclingCarbonService.selectBRecyclingCarbonList(bRecyclingCarbon);
        return getDataTable(list);
    }



    /**
     * 导出回收利用碳汇列表
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:export')")
    @Log(title = "回收利用碳汇", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BRecyclingCarbon bRecyclingCarbon)
    {
        List<BRecyclingCarbon> list = bRecyclingCarbonService.selectBRecyclingCarbonList(bRecyclingCarbon);
        ExcelUtil<BRecyclingCarbon> util = new ExcelUtil<BRecyclingCarbon>(BRecyclingCarbon.class);
        return util.exportExcel(list, "carbon");
    }

    /**
     * 上传保存数据
     * @param excel
     * @return
     */
    @PostMapping("/changeData")
    public AjaxResult changeDataByProjectId(@RequestBody WeatherDataExcel excel) {
        return bRecyclingCarbonService.changeDataByProjectId(excel);
    }


    /**
     * 获取回收利用碳汇详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bRecyclingCarbonService.selectBRecyclingCarbonById(id));
    }

    /**
     * 新增回收利用碳汇
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:add')")
    @Log(title = "回收利用碳汇", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BRecyclingCarbon bRecyclingCarbon)
    {
        return toAjax(bRecyclingCarbonService.insertBRecyclingCarbon(bRecyclingCarbon));
    }

    /**
     * 修改回收利用碳汇
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:edit')")
    @Log(title = "回收利用碳汇", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BRecyclingCarbon bRecyclingCarbon)
    {
        return toAjax(bRecyclingCarbonService.updateBRecyclingCarbon(bRecyclingCarbon));
    }

    /**
     * 删除回收利用碳汇
     */
    //  @PreAuthorize("@ss.hasPermi('recycling:carbon:remove')")
    @Log(title = "回收利用碳汇", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bRecyclingCarbonService.deleteBRecyclingCarbonByIds(ids));
    }
}
